'use strict';

angular.module('com.lx.ngsl.autopaper.controller',[])
 .controller('autopaperController',['$scope','$http','$location','$alert','autopaperService',function($scope,$http,$location,$alert,autopaperService) {
//	    function addUser(){
//     $("#crdtLogMx").modal("show");
//     console.log("sss");
// }
// function viewUser(item){
//     $("#crdtLogMx").modal("show");
//
// }
	$scope.pageChanged = function() {
		$scope.query($scope.currentPage);
	};
	$scope.query = function(page) {
		page = page ? (page-1) : 0;
		$http({
			method:"GET",
			url:"/ngsl/autopaper/query",
			params:{
				"page":page,
				"size":$scope.pagesize,
			}
		}).success(function(data, status) {
					$scope.items = data.content;
					console.log($scope.items);
					$scope.totalItems = data.totalElements;
				}).error(function(data, status) {
					alert(data.error);
					$scope.data = data || "Request failed";
					$scope.status = status;
		});
	};
	$scope.query($scope.currentPage);
 $scope.addPaper=function(){
 	if($scope.editItem.title==''||$scope.editItem.title==undefined){
 		$alert.error({message:'请填写试卷编号'});
 		return;
 	}
 	$http({
 		method:"GET",
 		url:"/ngsl/autopaper/add",
 		params:{'title':$scope.editItem.title}
 	}).success(function(data,status){
 		$alert.tip("添加试卷成功");
 		$scope.query($scope.currentPage);
 	}).error(function(data,status){
 		$alert.error({message:"添加试卷失败"});
 	})
 }
 $scope.delpaper=function(item){
	 $http({
		 method:"GET",
		 url:"/ngsl/autopaper/dele",
		 params:{"Id":item.id}
	 }).success(function(data,status){
		 $alert.tip("删除试卷成功");
		 $scope.query($scope.currentPage);
	 }).error(function(data,status){
	 		$alert.error({message:"删除试卷失败"});
	 	})
 }
 }])